﻿using System;
using NBus.Practice.GreetingMessage;
using NServiceBus;

namespace NBus.Practice.GreetingSender
{
    class Program
    {
        static void Main(string[] args)
        {
            var busConfiguration = new BusConfiguration();
            busConfiguration.EndpointName("Nbus.Practice.HelloWorld.Client");
            busConfiguration.UseSerialization<JsonSerializer>();
            busConfiguration.UsePersistence<InMemoryPersistence>();

            using (IBus bus = Bus.Create(busConfiguration).Start())
            {
                SendGreetingCommand(bus);
            }
        }

        private static void SendGreetingCommand(IBus bus)
        {
            Console.WriteLine("Press 'Enter' to send a message.To exit, Ctrl + C");
            var i = 0;
            while (Console.ReadLine() != null)
            {
                var id = Guid.NewGuid();
                bus.Send(new GreetingCommand() { Id = id, Times = i });
                i++;
                Console.WriteLine("Send a new GreetingCommand message with id: {0}", id.ToString("N"));
            }
        }
    }
}
